import { PicEntity } from './../entities/pic.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Injectable } from '@nestjs/common';
import SpecEntity from 'src/entities/spec.entity';

@Injectable()
export class SpecService {
  constructor(
    @InjectRepository(SpecEntity)
    private readonly SpecRepo: Repository<SpecEntity>,
    @InjectRepository(PicEntity)
    private readonly PicRepo: Repository<PicEntity>,
  ) {}
  // 创建一个规格实体 并不写入sq
  async createSpec(resolution: string, img_url: string) {
    try {
      const spec = new SpecEntity();
      spec.resolution = resolution;
      spec.img_url = img_url;
      return spec;
    } catch (e) {
      return Promise.reject(e);
    }
  }
  async getList(id: number) {
    try {
      const res = await this.PicRepo.findOne(id, {
        relations: ['specs'],
      });
      return res.specs;
    } catch (e) {
      return Promise.reject(e);
    }
  }
}
